#ifndef	APP_EXCEPTION_H
#define APP_EXCEPTION_H

#include <exception>
#include <iostream>
#include <string>

// @author rannou_s
// Overload of std::exception adding some features such as logging
// Must be called using the following macro, with e as the class inheriting of AppException

#define	EXCEPTION(e)		e(__LINE__, __FILE__)

class				AppException: public std::exception
{
private:
  int				mLine;
  const char *			mFile;
  std::string			mDate;
  std::string			mDiag;

  static std::ofstream		mOutputStream;
  static bool			mLog;

  AppException(void);
  std::string			getDate() const;
  virtual void			buildDiag(void);

public:  
  AppException(int, const char *);
  AppException(const AppException &);
  AppException &		operator=(const AppException &);
  virtual ~AppException() throw();

  virtual const char *		what(void) const throw();
  virtual void			log(void) const;
  virtual void			dump(void) const;
  friend std::ostream &		operator<<(std::ostream &, const AppException &);

  static void			activateLog(void);
  static void			desactivateLog(void);
  static void			setLogFile(const char *);
};

#endif // APP_EXCEPTION_H
